// pages/waybillBookingDetail/waybillBookingDetail.ts
var url = require("../../utils/urls");
var commons = require("../../utils/common");
var tip = require("../../utils/tip");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    feeTypeData: [],
    total: 0,
    waybillNumber: "",
    show: false,
    current: 1,
    size: 10,
    totalPage: 0
  },

  getListKeepAccounts() {
    let data = {
      current: this.data.current,
      size: this.data.size,
      waybillNumber: this.data.waybillNumber
    }
    commons.get(url.getKeepAccounts, data).then((res) => {
      this.setData({
        list: [],
        show: true
      })
      let resData = res.data
      if (resData.keepAccountsIPage.records.length > 0) {
        resData.keepAccountsIPage.records.forEach((a, key) => {
          a.proofImg = a.proofImg.split(',')
        })

        let total = 0
        resData.keepAccountsByParamsRespVOS.forEach((item, index) => {
          total = commons.NumberAdd(total, item.userMoney)
        })
        this.setData({
          list: this.data.list.concat(resData.keepAccountsIPage.records),
          totalPage: Math.ceil(resData.keepAccountsIPage.total / this.data.size),
          feeTypeData: resData.keepAccountsByParamsRespVOS,
          total: total
        })
      }
    }).catch(err => {

    });
  },

  getDictModel() {
    let data = {
      code: "expense_type"
    }
    commons.get(url.dictModel, data).then((res) => {
      let resData = res.data

      this.setData({
        feeTypeData: resData
      })
    }).catch(err => {

    });
  },

  goWaybillBookingDetail(e) {
    let item = e.currentTarget.dataset.item
    wx.navigateTo({
      url: "../bookOpr/bookOpr?item=" + JSON.stringify(item),
    })
  },

  loadMore(e) {
    console.log('加载更多')
    if (this.data.totalPage === 1) {
      return
    }

    if (this.data.current < this.data.totalPage) {
      this.setData({
        current: this.data.current + 1,
      })
      this.getListKeepAccounts()
      console.log(this.data.current, '当前页')
    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {
    if (e.waybillNumber) {
      this.setData({
        waybillNumber: e.waybillNumber
      })
      // this.getDictModel()
      this.getListKeepAccounts()
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.setData({
      current: 1,
      list: []
    })
    this.getListKeepAccounts()
    setTimeout(() => {
      wx.stopPullDownRefresh()
    }, 1000)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})